package com.pzhu.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.pzhu.pojo.User;

public class MainServlet extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		//设置请求编码格式
		req.setCharacterEncoding("utf-8");
		//设置响应编码格式
		resp.setContentType("text/html;charset=utf-8");
		//获取Session对象
		HttpSession hs=req.getSession();
		System.out.println(hs.getId());
		//获取Session对象中的数据，user键名存储的是u对象的值，强转成User对象类型
		User u=(User) hs.getAttribute("user");
		//响应处理结果
		resp.getWriter().write("<html>");
		resp.getWriter().write("<head>");
		resp.getWriter().write("</head>");
		resp.getWriter().write("<body>");
		//登录提示语，获取u对象里的用户名
		resp.getWriter().write("<h3>欢迎"+u.getUname()+"登录</h3>");
		resp.getWriter().write("<hr/>");
		resp.getWriter().write("<form action='show' method='get'>");
		resp.getWriter().write("<input type='submit' value='查看个人信息'>");
		resp.getWriter().write("</form>");
		resp.getWriter().write("</body>");
		resp.getWriter().write("</html>");

	}

}
